/*
 * Project: BoboDesignPattern
 * 
 * File Created at 2019年3月4日
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */
package test.lesson3.sort;

import java.util.Arrays;

/**
 * @Type QuickSort
 * @Desc
 * @author 52489
 * @date 2019年3月4日
 * @Version V1.0
 */
public class QuickSort {

    public static void main(String[] args) {
        int nums[] = { 2, 1, 4, 6, 4, 7, 8, 5, 10, 11 };
        sort(nums, 0, nums.length - 1);
        System.out.println(Arrays.toString(nums));
    }

    public static void sort(int nums[], int startIndex, int endIndex) {
        if (startIndex < endIndex) {

            int stardd = nums[startIndex];
            int lowIdx = startIndex;
            int highIdx = endIndex;
            while (lowIdx < highIdx) {
                while (lowIdx < highIdx && stardd <= nums[highIdx]) {
                    highIdx--;
                }
                nums[lowIdx] = nums[highIdx];
                while (lowIdx < highIdx && nums[lowIdx] <= stardd) {
                    lowIdx++;
                }
                nums[highIdx] = nums[lowIdx];
            }

            nums[lowIdx] = stardd;
            // 排标准数左和右

            sort(nums, startIndex, lowIdx);
            sort(nums, lowIdx + 1, endIndex);

        }
    }

}
